package com.itheima.pinda.log;


import com.itheima.pinda.auth.client.EnableAuthClient;
import com.itheima.pinda.log.aspect.LoginLogAspect;
import com.itheima.pinda.log.aspect.SysLogAspect;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;

/**
 * 日志自动配置
 * <p>
 * 启动条件：
 * 1，存在web环境
 * 2，配置文件中pinda.log.enabled=true
 * 3，配置文件中不存在：pinda.log.enabled 值
 * .   matchIfMissing = true, 就是对配置文件不存在 pinda.log.enabled这个值, 默认为true, 这样就能注入bean了
 */
@EnableAsync
@Configuration
@EnableAuthClient   // 开启解析token的注解开关
@AllArgsConstructor
@ConditionalOnWebApplication
@ConditionalOnProperty(name = "pinda.log.enabled", havingValue = "true", matchIfMissing = true)
public class LogAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public SysLogAspect sysLogAspect() {
        return new SysLogAspect();
    }

    @Bean
    @ConditionalOnMissingBean
    public LoginLogAspect loginLogAspect() {
        return new LoginLogAspect();
    }
}
